package network;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Configuration {
    private static final String configurationName = "config.prop";
    private static final String addressFieldName = "address", portFieldName = "port",
            historyFieldName = "historyFile", errorFieldName = "errorFile";

    private static String address = "localhost";
    private static int port = 888;
    private static String historyFileName = "C:\\Users\\Student\\Desktop\\log_file.log";
    private static String errorFileName = "C:\\Users\\Student\\Desktop\\error_file.log";

    public static void loadConfiguration() {
        try {
            FileInputStream inputStream = new FileInputStream(configurationName);
            if (inputStream == null) throw new IOException();
            Properties properties = new Properties();
            properties.load(inputStream);
            address = properties.getProperty(addressFieldName);
            port = Integer.parseInt(properties.getProperty(portFieldName));
            historyFileName = properties.getProperty(historyFieldName);
            errorFileName = properties.getProperty(errorFieldName);
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("Couldn't load configuration file");
        }
    }

    public static String getHistoryFileName() {
        return historyFileName;
    }

    public static String getErrorFileName() {
        return errorFileName;
    }

    public static String getAddress() {
        return address;
    }

    public static int getPort() {
        return port;
    }
}
